package com.gaff.emp.core.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gaff.emp.core.PageR;
import com.gaff.emp.core.modules.sys.dao.SysLogDao;
import com.gaff.emp.core.modules.sys.entity.SysLog;
import com.gaff.emp.core.modules.sys.service.SysLogService;
import com.gaff.emp.core.util.PageQuery;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogDao sysLogDao;

    @Override
    public PageR queryLogsByPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        IPage<SysLog> page = sysLogDao.selectPage(
                PageQuery.<SysLog>getPage(params),
                Wrappers.<SysLog>query()
                        .like(StringUtils.isNotBlank(key), "username", key)
                        .or()
                        .like(StringUtils.isNotBlank(key), "operation", key)
                        .orderByDesc("id"));
        return new PageR(page);
    }

}
